/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package se392.ateam2006.utils;
import java.util.GregorianCalendar;
import se392.ateam2006.exceptions.InvalidDayException;

/**
 * Utility methods used throughout the application
 * @author James Oliver, Adam Tilt, Edward Dell'Anno, Peter Moore, Sam Allen, Chris Heighway, Anthony Hodson, Mike Roberts.
 */
public class SystemUtils {
    
    private static String MONDAY = "monday";
    private static String TUESDAY = "tuesday";
    private static String WEDNESDAY = "wednesday";
    private static String THURSDAY = "thursday";
    private static String FRIDAY = "friday";
    private static String SATURDAY = "saturday";
    private static String SUNDAY = "sunday";
    private static Clock systemClock = new SystemClock();
    
    public static void setClock(Clock clock){
        systemClock = clock;
    }
    
    public static Clock getClock(){
        return systemClock;
    }
    
    public static String dayStringBuilder(String d) throws InvalidDayException{
        
        String[] days = d.split(" ");
        String dayNumbers = "";
        
        for (int i = 0; i < days.length; i++) {
            
            String currentDay = days[i].trim();            
            
            if(currentDay.equalsIgnoreCase(MONDAY)){
                dayNumbers += GregorianCalendar.MONDAY;
            }else if(currentDay.equalsIgnoreCase(TUESDAY)){
                dayNumbers += GregorianCalendar.TUESDAY;
            }else if(currentDay.equalsIgnoreCase(WEDNESDAY)){
                dayNumbers += GregorianCalendar.WEDNESDAY;
                
            }else if(currentDay.equalsIgnoreCase(THURSDAY)){
                
                dayNumbers += GregorianCalendar.THURSDAY;
            }else if(currentDay.equalsIgnoreCase(FRIDAY)){
                
                dayNumbers += GregorianCalendar.FRIDAY;
            }else if(currentDay.equalsIgnoreCase(SATURDAY)){
                
                dayNumbers += GregorianCalendar.SATURDAY;
            }else if(currentDay.equalsIgnoreCase(SUNDAY)){
                dayNumbers += GregorianCalendar.SUNDAY;
            } else {
                throw new InvalidDayException("you have specified an invalid day");
            }
            
            if(!(i == days.length - 1)){
                dayNumbers += ",";
            }
            
        }
        
        return dayNumbers;
    }
}
